package com.moon;

import java.util.ArrayList;
import java.util.List;

import cn.yueliangbaba.R;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

public class PhotoActivity extends BaseActivity {
	private List<View> mListViews;  
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_photo);
		
		((Button)findViewById(R.id.right)).setCompoundDrawablesWithIntrinsicBounds(R.drawable.btn_more, 0, 0, 0);
		((TextView) findViewById(R.id.center)).setText("3班(1/4)");
		
		mListViews = new ArrayList<View>();

		LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View convertView = mInflater.inflate(R.layout.item_photo, null);
		mListViews.add(convertView);
		
		convertView = mInflater.inflate(R.layout.item_photo, null);
		mListViews.add(convertView);
		
		convertView = mInflater.inflate(R.layout.item_photo, null);
		mListViews.add(convertView);
		
		convertView = mInflater.inflate(R.layout.item_photo, null);
		mListViews.add(convertView);
		
		ViewPager viewPager = (ViewPager)findViewById(R.id.vp);
		viewPager.setAdapter(new MyViewPagerAdapter());  
		viewPager.setOnPageChangeListener(new OnPageChangeListener(){

			@Override
			public void onPageScrollStateChanged(int arg0) {
				
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				
			}

			@Override
			public void onPageSelected(int arg0) {
				int index = arg0 + 1;
				((TextView) findViewById(R.id.center)).setText("3班(" + index + "/4)");
			}});
	}
	
	public class MyViewPagerAdapter extends PagerAdapter{  
        public MyViewPagerAdapter() {  
        }  
  
        @Override  
        public void destroyItem(ViewGroup container, int position, Object object)   {     
            container.removeView(mListViews.get(position));//删除页卡  
        }  
  
  
        @Override  
        public Object instantiateItem(ViewGroup container, int position) {  //这个方法用来实例化页卡         
             container.addView(mListViews.get(position), 0);//添加页卡  
             return mListViews.get(position);  
        }  
  
        @Override  
        public int getCount() {           
            return  mListViews.size();//返回页卡的数量  
        }  
          
        @Override  
        public boolean isViewFromObject(View arg0, Object arg1) {             
            return arg0==arg1;//官方提示这样写  
        }  
    }  
}
